package org.carl.component.job.service

import com.xxl.job.core.executor.XxlJobExecutor
import org.carl.component.job.vo.XxlJobGroup
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean
import org.springframework.http.ResponseEntity
import org.springframework.stereotype.Component


/**
 * email carl.chen@bk.ru
 * @Author: 陈青松
 * @Date: 2019/1/19 2:57
 */
@ConditionalOnBean(value = [XxlJobExecutor::class])
@Component
open class JobGroupService : JobService() {

    //保存
    private val save = "/jobgroup/save"
    //修改
    private val update = "/jobgroup/update"
    //删除
    private val remove = "/jobgroup/remove"
    //查询所有
    private val findAll = "/jobgroup/findAll"

    /**
     * 保存
     */
    fun save(xxlJobGroup: XxlJobGroup): ResponseEntity<String> {
        var request = handleHttpEntity(xxlJobGroup)
        return restTemplate!!.postForEntity(getLoadUrl(save), request, String::class.java, arrayOfNulls<Any>(0))
    }

    /**
     * 修改
     */
    fun update(xxlJobGroup: XxlJobGroup): ResponseEntity<String> {
        var request = handleHttpEntity(xxlJobGroup)
        return restTemplate!!.postForEntity(getLoadUrl(update), request, String::class.java, arrayOfNulls<Any>(0))
    }

    /**
     * 删除
     */
    fun remove(id: Int): ResponseEntity<String> {
        val paramMap = mapOf("id" to id)
        var request = handleHttpEntity(paramMap)
        return restTemplate!!.postForEntity(getLoadUrl(remove), request, String::class.java, arrayOfNulls<Any>(0))
    }

    /**
     * 查询所有
     */
    fun findAll(): ResponseEntity<String> {
        var request = handleHttpEntity(this.xxlConfigVo!!)
        return restTemplate!!.postForEntity(getLoadUrl(findAll), request, String::class.java, arrayOfNulls<Any>(0))
    }


}
